package com.icsss.test1.controller;

import com.icsss.test1.pojo.Person;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;
import java.util.Map;
import java.util.Set;

@RestController
public class StoreController {

    @Autowired
    RestTemplate restTemplate;

    @GetMapping("/client1/getobj.action")
    public Object client12(){
        String url = "http://test2/client1/getObj";
        ResponseEntity<Person> responseEntity = restTemplate.getForEntity(url, Person.class);
        Person body = responseEntity.getBody();
        System.out.println("body:" + body);
        HttpStatus statusCode = responseEntity.getStatusCode();
        System.out.println("HttpStatus:" + statusCode);
        int statusCodeValue = responseEntity.getStatusCodeValue();
        System.out.println("statusCodeValue:" + statusCodeValue);
        System.out.println("----------------header------------------");
        HttpHeaders headers = responseEntity.getHeaders();
        Set<Map.Entry<String, List<String>>> entries = headers.entrySet();
        for (Map.Entry<String, List<String>> entry:entries) {
            System.out.println(entry.getKey());
            System.out.println(entry.getValue());
        }
        return body;
    }
}